import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { BaseItem } from "../../common/BaseItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { NumInput } from "../../common/NumInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ItemData } from "../../../resource/info/ItemData";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EGuildWarehouseOper } from "../../../../../Message/Game/EGuildWarehouseOper";
//class ContriConfirmWindow
    
    export  class ContriConfirmWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public init(): void
        {
            this.setSize(295, 175);
            this.titleHeight = 28;
            this.title = Language.getString(57258);
            this._bg = ObjCreate.createBg(18, 40, 258, 125, this);
            this._baseItem = new BaseItem();
            this._baseItem.width = 38;
            this._baseItem.height = 38;
            this._baseItem.move(32, 80);
            this.addChild(this._baseItem);
            this._tipTxt = ObjCreate.createTextField("", 20, 45, 248, 20, this, GlobalStyle.textFormat6);
            this._tipTxt.htmlText = Language.getString(57259);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.wordWrap = true;
            this._tipTxt.multiline = true;
            this._nameTxt = ObjCreate.createTextField("", 90, 80, 170, 20, this);
            this._numLabel = ObjCreate.createTextField(Language.getString(57260), 90, 100, 170, 20, this);
            this._numStepper = new NumInput();
            this._numStepper.maxNum = 99;
            this._numStepper.x = 150;
            this._numStepper.y = 100;
            this.addChild(this._numStepper);
            this._okBtn = new GButton();
            this._okBtn.label = Language.getString(57239);
            this._okBtn.name = "SaleButton";
            this._okBtn.styleName = "Button";
            this._okBtn.setSize(48, 27);
            this._okBtn.move(65, 130);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this.addChild(this._okBtn);
            this._cancelBtn = new GButton();
            this._cancelBtn.label = Language.getString(57240);
            this._cancelBtn.name = "SaleButton";
            this._cancelBtn.styleName = "Button";
            this._cancelBtn.setSize(48, 27);
            this._cancelBtn.move(160, 130);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this.addChild(this._cancelBtn);
            return;
        }

        public updateByItemData(arg1: ItemData): void
        {
            if (arg1) 
            {
                this._itemData = arg1;
                this._nameTxt.htmlText = HTMLUtil.addColor(arg1.itemInfo.item.name, ColorConfig.instance.getItemColor(arg1.itemInfo.item.color).color);
                this._numStepper.maxNum = arg1.itemAmount;
                this._baseItem.itemData = arg1;
                this._baseItem.amount = -1;
                if (this._itemData.itemInfo.item.color >= 4) 
                {
                    this.reset(true);
                }
                else 
                {
                    this.reset(false);
                }
            }
            return;
        }

        /* internal  */reset(arg1: Boolean): void
        {
            if (arg1) 
            {
                this.height = 175;
                this._bg.height = 125;
                this._baseItem.y = 80;
                this._nameTxt.y = 80;
                this._tipTxt.visible = true;
                this._numLabel.y = 100;
                this._numStepper.y = 100;
                this._okBtn.y = 130;
                this._cancelBtn.y = 130;
            }
            else 
            {
                this.height = 145;
                this._bg.height = 95;
                this._baseItem.y = 50;
                this._nameTxt.y = 50;
                this._tipTxt.visible = false;
                this._numLabel.y = 70;
                this._numStepper.y = 70;
                this._okBtn.y = 100;
                this._cancelBtn.y = 100;
            }
            return;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._itemData) 
            {
                loc1 = this._itemData.data;
                loc1.itemAmount = this._numStepper.currentNum;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseOper, {"oper": EGuildWarehouseOper.convert(EGuildWarehouseOper._EGuildWarehouseIn), "item": loc1}));
            }
            hide();
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            hide();
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_titleTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_numStepper: NumInput;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_numLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemData: ItemData;
    }
